package com.lb.activity.mapper;

import com.lb.activity.po.Permission;
import com.lb.activity.po.PermissionExample;
import org.apache.ibatis.annotations.Delete;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.ResultMap;
import org.apache.ibatis.annotations.Select;

import java.util.List;

public interface PermissionMapper {
    int countByExample(PermissionExample example);

    int deleteByExample(PermissionExample example);

    int deleteByPrimaryKey(Long id);

    int insert(Permission record);

    int insertSelective(Permission record);

    List<Permission> selectByExample(PermissionExample example);

    Permission selectByPrimaryKey(Long id);

    int updateByExampleSelective(@Param("record") Permission record, @Param("example") PermissionExample example);

    int updateByExample(@Param("record") Permission record, @Param("example") PermissionExample example);

    int updateByPrimaryKeySelective(Permission record);

    int updateByPrimaryKey(Permission record);

    @Delete("delete from ROLE_PERMISSION where PERMISSIONID = #{permissionId,jdbcType=DECIMAL}")
    void deleteRolePermiss(Long id);


    @Select("select distinct sap.id , sap.parentid, sap.name, sap.url,sap.percode,sap.type,sap.icon,sap.sort \n" +
            "\t\tfrom permission sap\n" +
            "\t\tleft join ROLE_PERMISSION srp on sap.id = srp.permissionid \n" +
            "\t\tleft join role sar on sar.id =  srp.roleid\n" +
            "\t\tleft join USER_ROLE sur on sur.roleid=sar.id\n" +
            "\t\tleft join user sau on sau.id=sur.userid where sau.id = #{id}\n" +
            "\t\tand sap.status = 0\n" +
            "\t\torder by sap.sort asc")
    @ResultMap("com.lb.activity.mapper.PermissionMapper.BaseResultMap")
    List<Permission> listMenuByUserId(Long userId);


    @Select("select PERMISSIONID from ROLE_PERMISSION where ROLEID = #{id}")
    List<Long> listMenuIdByRoleId(Long id);

    @Delete(" delete from ROLE_PERMISSION\n" +
            "    where roleid = #{roleId,jdbcType=DECIMAL}")
    void removeByRoleId(Long roleId);
}